class Solution {
public:
    int numRabbits(vector<int>& answers) {
        unordered_map<int,int> rec;
        for(int& num : answers){
            rec[num]++;
        }
        
        int n = answers.size();
        unordered_set<int> vis;
        int ans = 0;
        for(int i = 0;i < n;i++){
            if(vis.count(answers[i])) continue;
            int k = answers[i]+1;
            int num = rec[answers[i]];
            
            if(num % k == 0){
                ans += num;
            }else{
                ans += (num / k + 1)* k;
            }
            vis.insert(answers[i]);
        }
        
        return ans;
    }
};
